#include<stdio.h>
#include<stdlib.h>
#include "../include/linked_block.h"

//add free block
Free_Block * add_free_block( Free_Block * block_head,int block_number) /*insert at beginning */
{
    Free_Block * temp;
    temp=(Free_Block *)malloc(sizeof(Free_Block));
    
    temp->block_number = block_number;
    if (block_head== NULL)
    {
    block_head=temp;
    block_head->next=NULL;
    }
    else
    {
    temp->next=block_head;
    block_head=temp;
    }
   return block_head;
}

int search_blocks(int blockindex,Free_Block * block_head)
{
  
  Free_Block * temp;
  temp=block_head;
  
  while(temp!=NULL)
  {
    if(temp->block_number==blockindex)
     return 1;
    temp=temp->next;
  }		

 return 0;
}

int countFreeBlocks(Free_Block * block_head)
{
  
    
  Free_Block * temp;
  temp=block_head;
  int count=0;
  while(temp!=NULL)
  {
    count++;
    temp=temp->next;
  }		
 return count;
}

/*delete a block from block list*/
int get_free_block(Free_Block ** block_head)
{	
	int bno;
    if(*block_head ==NULL){
     return -1;
	}
	
    bno=(*block_head)->block_number;
    (*block_head)=(*block_head)->next;
    return bno; 
    
}



